package com.athena.web.controller.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.athena.dal.dao.GenericDao;
import com.athena.dal.entities.Faculty;
import com.athena.dal.entities.Student;
import com.athena.dal.entities.User;

/**
 * Represents the common user of athena product.
 * 
 * @author Pankaj.Mishra
 * 
 */
public class AthenaUser implements UserDetails {

	
	User user;
	
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		List<GrantedAuthorityImpl> list = new ArrayList<GrantedAuthorityImpl>();
		GrantedAuthorityImpl authorityImpl = new GrantedAuthorityImpl("ROLE_USER");
		list.add(authorityImpl);
		return list;
	}

	@Override
	public String getPassword() {
		return user.getPassword();
	}

	@Override
	public String getUsername() {
		return user.getUsername();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}



	class GrantedAuthorityImpl implements GrantedAuthority {
		String role;

		public GrantedAuthorityImpl(String role) {
			this.role = role;
		}

		@Override
		public String getAuthority() {
			return role;
		}

	}
}
